package com.hbsx.why;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.hbsx.why.base.BaseActivity;
import com.hbsx.why.ui.activity.ActivityFragment;
import com.hbsx.why.ui.home.HomeFragment;
import com.hbsx.why.ui.mine.MineFragment;
import com.hbsx.why.ui.find.FindFragment;
import com.hbsx.why.utils.alphatabs.AlphaTabsIndicator;
import com.hbsx.why.utils.alphatabs.OnTabChangedListner;

import java.util.ArrayList;
import java.util.List;
/**
 * @author LIUB
 * @desc demo
 * @time 2017/12/25 10:43
 */
public class NormalMainActivity extends BaseActivity {
    private static AlphaTabsIndicator alphaTabsIndicator;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_main_normal;
    }

    @Override
    public void initView() {
        ViewPager mViewPger = (ViewPager) findViewById(R.id.mViewPager);
        MainAdapter mainAdapter = new MainAdapter(getSupportFragmentManager());
        mViewPger.setAdapter(mainAdapter);
        mViewPger.addOnPageChangeListener(mainAdapter);

        alphaTabsIndicator = (AlphaTabsIndicator) findViewById(R.id.alphaIndicator);
        alphaTabsIndicator.setViewPager(mViewPger);

        alphaTabsIndicator.getTabView(0).showNumber(6);
        alphaTabsIndicator.getTabView(1).showNumber(888);
        alphaTabsIndicator.getTabView(2).showNumber(88);
        alphaTabsIndicator.getTabView(3).showPoint();
        alphaTabsIndicator.setTabCurrenItem(0);
        alphaTabsIndicator.setOnTabChangedListner(new OnTabChangedListner() {
            @Override
            public void onTabSelected(int tabNum) {
                alphaTabsIndicator.setCurrenItem(tabNum);
            }
        });
    }


    @Override
    protected void onResume() {
        super.onResume();
//        HttpAdapter.getSerives().getWeatherParams("SpinerWeather").enqueue(new OnResponseListener<BaseCodeModel<WeatherBean>>() {
//            @Override
//            protected void onSuccess(BaseCodeModel<WeatherBean> weatherBeanBaseCodeModel) {
//                mainText2.setText(weatherBeanBaseCodeModel.getData().get(0).getWinds());
//                LogUtils.logi(weatherBeanBaseCodeModel.getData().size() + "");
//            }
//        });
    }

    private class MainAdapter extends FragmentPagerAdapter implements ViewPager.OnPageChangeListener {

        private List<Fragment> fragments = new ArrayList<>();
        private String[] titles = {"微信", "通讯录", "发现", "我"};

        public MainAdapter(FragmentManager fm) {
            super(fm);
            fragments.add(HomeFragment.newInstance(titles[0], 1));
            fragments.add(ActivityFragment.newInstance(titles[1], 1));
            fragments.add(FindFragment.newInstance(titles[2], 1));
            fragments.add(MineFragment.newInstance(titles[3], 1));
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (0 == position) {
                alphaTabsIndicator.getTabView(0).removeShow();
                //alphaTabsIndicator.getTabView(0).showNumber(alphaTabsIndicator.getTabView(0).getBadgeNumber() - 1);
            } else if (1 == position) {
                alphaTabsIndicator.getTabView(1).removeShow();
            } else if (2 == position) {
                alphaTabsIndicator.getTabView(2).removeShow();
            } else if (3 == position) {
                alphaTabsIndicator.getTabView(3).removeShow();
                //alphaTabsIndicator.removeAllBadge();
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    }

    public static void setTab(int position) {
        alphaTabsIndicator.setTabCurrenItem(position);
    }
}
